﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Newtonsoft.Json;
using LiuYan.Entity;
using LiuYan.Service;

namespace LiuYan.Web.Areas.Admin.Controllers
{
    public class AdminController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Window(int id)
        {
            ViewData["role"] = new RoleService().GetAllList();
            ViewData["id"] = id;
            return View();
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pageCount"></param>
        /// <param name="pageIndex"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetList(int pageIndex, int pageCount, string name, string username)
        {
            return JsonConvert.SerializeObject(new AdminService().GetList(pageIndex, pageCount, username, name));
        }
        public int Edit(FormCollection form)
        {

            TB_Admin entity = new TB_Admin();
            entity.Id = Convert.ToInt32(form["id"]);
            entity.Del = 0;
            entity.Name = form["name"];
            entity.UserName = form["username"];
            entity.IsExit = Convert.ToInt32(form["qy"]);
            entity.RoleId = Convert.ToInt32(form["role"]);
            entity.Date = DateTime.Now;
            entity.Remark = form["remark"];
            entity.PassWord = form["password"];
            entity.Tell = form["tell"];
            if (entity.Id == 0)
            {
                if (new AdminService().CheckRegistUser(form["username"]) > 0)
                {
                    return -2;
                }
            }

            return new AdminService().Edit(entity);
        }
        public int Del(string ids)
        {
            return new BaseService().Dels(ids, "TB_Admin", false);
        }
        public string GetOneData(int id)
        {
            return JsonConvert.SerializeObject(new BaseService().GetOneData(id, "TB_Admin"));
        }

        public int RevertPwd(int id)
        {
            return new AdminService().RevertPwd(id);
        }
    }
}